class Solution {
    public int findMaxForm(String[] strs, int m, int n) {
        int len = strs.length;
        int[][] dp = new int[m + 1][n + 1];
        for(int i = 1; i <= len; i++){
            int nums1 = get1(strs[i - 1]);
            int nums0 = strs[i - 1].length() - nums1;
            for(int j = m; j >= nums0; j--){
                for(int k = n; k >= nums1; k--){
                    dp[j][k] = Math.max(dp[j][k], dp[j - nums0][k - nums1] + 1);
                }
            }
        }
        return dp[m][n];
    }
    public int get1(String s){
        char[] ch = s.toCharArray();
        int count = 0;
        for(int i = 0; i < ch.length; i++){
            if(ch[i] == '1') count++;
        }
        return count;
    }
}